//
//  Semaphore.swift
//  ScaffoldKit
//
//  Created by SuXinDe on 2018/7/29.
//  Copyright © 2018年 su xinde. All rights reserved.
//

import Dispatch
import Foundation

public struct Semaphore {
    
    private let semaphore: DispatchSemaphore
    
    public init(poolSize: Int = 0) {
        semaphore = DispatchSemaphore(value: poolSize)
    }
    

    @discardableResult
    public func wait() -> DispatchTimeoutResult {
        return semaphore.wait(timeout: .distantFuture)
    }
    
    @discardableResult
    public func `continue`() -> Int {
        return semaphore.signal()
    }
    
}
